#ifndef RATINGVIEWWIDGET_H
#define RATINGVIEWWIDGET_H

#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QTableWidget>
#include <QLabel>
#include <QPushButton>
#include <QComboBox>
#include <QLineEdit>
#include <QDateEdit>
#include <QGroupBox>
#include <QProgressBar>
#include <QScrollArea>
#include <QTextEdit>
#include <QSplitter>
#include <QFrame>
#include <QHeaderView>
#include <QMessageBox>
#include <QTimer>
#include "ratingmanager.h"
#include "models.h"

using namespace RestaurantSystem;

/**
 * @brief 用户评价查看界面组件
 * 
 * 为管理员提供完整的用户评价查看和管理功能：
 * - 评价列表显示和筛选
 * - 评价统计信息
 * - 评价详情查看
 * - 评价搜索功能
 */
class RatingViewWidget : public QWidget
{
    Q_OBJECT

public:
    explicit RatingViewWidget(QWidget *parent = nullptr);
    ~RatingViewWidget();
    
    /**
     * @brief 设置评价管理器
     * @param manager RatingManager实例
     */
    void setRatingManager(RatingManager *manager);
    
    /**
     * @brief 刷新数据
     */
    void refreshData();

public slots:
    /**
     * @brief 处理评价数据变更信号
     */
    void onRatingCreated(const Rating &rating);
    void onRatingUpdated(const QString &ratingId, const Rating &oldRating, const Rating &newRating);
    void onRatingDeleted(const QString &ratingId);
    void onRatingsChanged();

private slots:
    /**
     * @brief 界面操作槽函数
     */
    void onSearchTextChanged();
    void onRatingFilterChanged();
    void onDateFilterChanged();
    void onRefreshClicked();
    void onExportClicked();
    void onTableItemDoubleClicked(int row, int column);

signals:
    /**
     * @brief 状态消息信号
     */
    void statusMessageChanged(const QString &message, int timeout = 0);

private:
    /**
     * @brief 界面初始化
     */
    void setupUI();
    void setupRatingTable();
    void setupFilterControls();

    void setupConnections();
    void applyStyles();
    
    /**
     * @brief 数据操作
     */
    void loadRatingData();
    void updateRatingTable();
    void filterRatingData();
    
    /**
     * @brief 辅助方法
     */
    void showStatusMessage(const QString &message, bool isError = false);
    int getSelectedRowIndex();
    QString getSelectedRatingId();
    void selectRating(const QString &ratingId);
    RatingSearchCriteria buildSearchCriteria();
    QString formatRatingStars(int rating);
    QString formatDateTime(const QDateTime &dateTime);

private:
    // 核心组件
    RatingManager *m_ratingManager;
    
    // 主布局
    QVBoxLayout *m_mainLayout;
    
    // 筛选控件
    QGroupBox *m_filterGroup;
    QHBoxLayout *m_filterLayout;
    QLineEdit *m_searchEdit;
    QComboBox *m_ratingFilter;
    QDateEdit *m_startDateEdit;
    QDateEdit *m_endDateEdit;
    QPushButton *m_refreshButton;
    QPushButton *m_exportButton;
    
    // 评价表格
    QTableWidget *m_ratingTable;
    

    
    // 数据和状态
    QList<Rating> m_allRatings;
    QList<Rating> m_filteredRatings;
    QString m_selectedRatingId;
    
    // 定时器
    QTimer *m_searchTimer;
    QTimer *m_refreshTimer;
    
    // 刷新状态标志
    bool m_isRefreshing;
    
    // 表格列索引
    enum TableColumn {
        COL_ID = 0,
        COL_CUSTOMER = 1,
        COL_ORDER = 2,
        COL_RATING = 3,
        COL_COMMENT = 4,
        COL_DATE = 5,
        COL_COUNT = 6
    };
};

#endif // RATINGVIEWWIDGET_H
